package com.china08.yxyapi.api.manage.tec.teaching.homework.worklist;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskClassRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskQuesRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskReportRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskRepository;

/**
 * 删除作业
 */
@CrossOrigin
@RestController
public class WorklistDelTaskController extends YxyApiBaseController {

    @Autowired
    HomeworkTaskQuesRepository homeworkTaskQuesRepository;

    @Autowired
    HomeworkTaskRepository homeworkTaskRepository;

    @Autowired
    HomeworkTaskReportRepository homeworkTaskReportRepository;

    @Autowired
    HomeworkTaskClassRepository homeworkTaskClassRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/homework/worklist/del", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(//
            HttpServletRequest request, //
            HttpServletResponse response, //
            @RequestParam String taskId, //
            @RequestParam String classId, //
            RespModel respModel) throws ParseException {

        try {
            // 删除 任务班级数据
            homeworkTaskClassRepository.deleteByTaskIdAndClassId(taskId, classId);
            // 删除 任务学生数据
            homeworkTaskReportRepository.deleteByTaskIdAndClassId(taskId, classId);
            // 删除 任务试题
            // homeworkTaskQuesRepository.deleteById(taskId);
            // 删除 任务
            // homeworkTaskRepository.deleteById(taskId);
        } catch (Exception e) {
            Assert.isTrue(false, "删除失败");
        }

        return respModel;
    }

    /** 响应 **/
    public static class RespModel extends YxyApiRespModel {
    }
}
